<?php
declare(strict_types=1);

namespace App\Library;

use Hyperf\HttpServer\Annotation\AutoController;
use function Hyperf\Support\env;
use Hyperf\Nacos\Application;
use Hyperf\Nacos\Config;
use Hyperf\Codec\Json;

#[AutoController]
class Nacos
{
    private static $instance = null;
    
    public static function getInstance()
    {
        if (self::$instance === null) {
            self::$instance = new self();
        }
        return self::$instance;
    }
	
    public function getConfig($dataId, $group='DEFAULT_GROUP')
    {
		$application = new Application(new Config([
			'username' => constant('NACOS_USERNAME'),
			'password' => constant('NACOS_PASSWORD'),
			'guzzle_config' => [
				'headers' => [
					'charset' => 'UTF-8',
		          ],
		     ],
		]));
	   $response = $application->config->get($dataId, $group);
	   return Json::decode((string) $response->getBody());
    }
}